package com.huike.service.activity.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.huike.dto.ActivityDTO;
import com.huike.mapper.activity.ActivityMapper;
import com.huike.pojo.Activity;
import com.huike.pojo.Activity_Channel;
import com.huike.pojo.Activity_Status;
import com.huike.pojo.Activity_Vouchers;
import com.huike.result.PageResult;
import com.huike.result.Result;
import com.huike.service.activity.ActivityService;
import com.huike.vo.ActivityVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {


    @Autowired
    private ActivityMapper activityMapper;

    //分页
    @Override
    public PageResult page(ActivityDTO dto) {

        PageHelper.startPage(dto.getPageNum(),dto.getPageSize());

        Page<ActivityVO> page=activityMapper.page(dto);

        return new PageResult(page.getTotal(),page.getResult(),200,"查询成功",null);
    }

    //查看渠道
    @Override
    public Result findChannel(Activity_Channel channel) {

        List<Activity_Channel> channel1 = activityMapper.findChannel(channel);
        Result result = new Result();
        result.setCode(200);
        result.setData(channel1);
        result.setMsg("成功");

        return result;
    }

    //查看代金券
    @Override
    public Result findVouchers(Activity_Vouchers vouchers) {
        List<Activity_Vouchers> vouchers1=activityMapper.findVouchers(vouchers);

        Result result = new Result();
        result.setCode(200);
        result.setData(vouchers1);
        result.setMsg("查询成功");
        return result;
    }


    //查看活动状态
    @Override
    public Result findStatus(Activity_Status status) {
        List<Activity_Status> status1=activityMapper.findStatus(status);

        Result result = new Result();
        result.setCode(200);
        result.setData(status1);
        result.setMsg("查询成功");
        return result;
    }

    //新增活动
    @Override
    public Result save(Activity activity) {
        activityMapper.save(activity);

        return Result.success();

    }

    //删除活动
    @Override
    public void delete(Long id) {
        activityMapper.delete(id);
    }


    //修改活动
    @Override
    public ActivityVO findById(Long id) {
        ActivityVO vo=activityMapper.findById(id);
        return vo;
    }


    //修改活动
    @Override
    public void update(Activity activity) {
        activityMapper.update(activity);
    }


}

